<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
	<#assign base=request.contextPath  />
		<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" />
		<meta name="misapplication-tap-highlight" content="no" />
		<meta name="HandheldFriendly" content="true" />
		<meta name="MobileOptimized" content="320" />
		<title>车企加盟</title>
		<link rel="stylesheet" type="text/css" href="${base}/Yang/layui/css/layui.css"/>
		<link rel="stylesheet" href="${base}/css/common.css" type="text/css" charset="utf-8" />
		<script src="${base}/Yang/layui/layui.js"></script>
		<script src="${base}/Yang/jquery-1.9.0.min.js"></script>
		<style type="text/css">
			.layui-input{
			    height: 38px;
			    line-height: 1.3;
			    line-height: 38px\9;
			    border-width: 1px;
			     border-style: none; 
			    background-color: #fff;
			    border-radius: 2px;
			}
			.layui-form-item{
				border-bottom: 1px solid #CCCCCC;
			}
			.layui-form-select dl dd.layui-this {
			    background-color: #9AC747;
			    color: #fff;
			}
            img {
                width: 125px;
                height: 70px;
				padding: 5px;
            }
            .layui-upload-drag {
                margin: 0px 10px 10px 0px;
            }
            .layui-upload-drag {
                position: relative;
                padding: 0px;
                width: 135px;
                height: 80px;
                border: 1px dashed #e2e2e2;
                background-color: #fff;
                text-align: center;
                cursor: pointer;
                color: #999;
            }
            .layui-upload-drag .layui-icon {
                font-size: 37px;
                color: #009688;
            }
            .content {
                text-align: center;
                padding-top: 0px;
            }
			.layui-form-item {
				margin-bottom: 0px;
				clear: both;
				*zoom: 1;
			}
			.layui-input-block {
				margin-left: 120px;
				min-height: 40px;
			}
			.layui-form-label {
				float: left;
				display: block;
				padding: 9px 15px;
				width: 90px;
				font-weight: 400;
				line-height: 20px;
				text-align: right;
			}
			.layui-btn{
				border-radius: 5px;
			}
			.layui-btn-sm {
				height: 26px;
				line-height: 26px;
				padding: 0 8px;
				font-size: 12px;
			}
		</style>
	</head>

	<body onselectstart="return false;">
	<div id="content" class="content">
		<form class="layui-form" action="">
		  <div class="layui-form-item">
		    <label class="layui-form-label">企业名称</label>
		    <div class="layui-input-block">
		      <input type="text" name="ptName"  id="ptName"lay-verify="企业名称" autocomplete="off" placeholder="请输入企业名称" class="layui-input">
		    </div>
		  </div>
		  <div class="layui-form-item">
		    <label class="layui-form-label">联系人姓名</label>
		    <div class="layui-input-block">
		      <input type="text" name="callName" id="callName" lay-verify="联系人姓名" autocomplete="off" placeholder="请输入联系人姓名" class="layui-input">
		    </div>
		  </div>
		  <div class="layui-form-item">
		    <label class="layui-form-label">联系人手机</label>
		    <div class="layui-input-block">
		      <input type="text" name="callPhone" id="callPhone" lay-verify="联系人手机" autocomplete="off" placeholder="请输入联系人手机" class="layui-input">
		    </div>
		  </div>
		

		    <div class="layui-form-item">
		    <label class="layui-form-label">加盟车型</label>
		    <div class="layui-input-block"style="width: 180px;">
		      <select name="carType" id="carType">
		        <option value="">请选择品牌</option>
		        <option value="4.2米箱式货车">4.2米箱式货车</option>
		        <option value="中面">中面</option>
		        <option value="小面">小面</option>
		      </select>
		    </div>
		  </div>
		  <div class="layui-form-item">
		    <label class="layui-form-label">加盟数量</label>
		    <div class="layui-input-block">
		      <input type="text" name="num"  id="num" lay-verify="加盟数量" autocomplete="off" placeholder="请输入加盟数量" class="layui-input">
		    </div>
		  </div>

            <div class="layui-form-item">
                <label class="layui-form-label">车辆名</label>
                <div class="layui-input-block">
                    <input id="carName" name="carName" lay-verify="车辆名"  placeholder="请输入车辆名" autocomplete="off" class="layui-input isNull " type="text">
                </div>
            </div>
            <#--<div class="layui-form-item">-->
                <#--<label class="layui-form-label">车牌号</label>-->
                <#--<div class="layui-input-block">-->
                    <#--<input id="carNumber" name="carNumber" lay-verify="车牌号"  placeholder="请输入车牌号" autocomplete="off" class="layui-input isNull " type="text">-->
                <#--</div>-->
            <#--</div>-->
            <div class="layui-form-item">
                <label class="layui-form-label">载重</label>
                <div class="layui-input-block">
                    <input id="carSize" name="carSize" lay-verify="载重"  placeholder="请输入载重" autocomplete="off" class="layui-input isNull " type="text">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">续航</label>
                <div class="layui-input-block">
                    <input id="carKm"  name="carKm" lay-verify="续航"  placeholder="请输入续航" autocomplete="off" class="layui-input isNull " type="text">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">轴距</label>
                <div class="layui-input-block">
                    <input id="base" name="base" lay-verify="轴距"  placeholder="请输入轴距" autocomplete="off" class="layui-input isNull " type="text">
                </div>

            </div>
            <#--<div class="layui-form-item">-->
                <#--<label class="layui-form-label">车辆价格</label>-->
                <#--<div class="layui-input-block">-->
                    <#--<input id="carMoeny" name="carMoeny" lay-verify="价格"  placeholder="请输入价格" autocomplete="off" class="layui-input isNull " type="text">-->
                <#--</div>-->

            <#--</div>-->
            <div class="layui-form-item">
                <label class="layui-form-label">有无保险</label>
                <div class="layui-input-block" style="width: 180px;">
                    <select name="insure" lay-filter="有无保险" id="insure">
                        <option value="2">无</option>
                        <option value="1" selected="">有</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">首页图片</label>
                <div class="layui-input-inline">
                    <div class="layui-upload-drag" id="uploadZZ" style="float: left;">
                        <i style="color: #9AC747" class="layui-icon"></i>
                        <p>点击上传图片</p>
					<#--   <i class="layui-icon layui-icon-loading" style="font-size: 30px; color: #9AC747;"></i>-->
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">轮播图片<br/></轮播图片br></label>
				<div class="layui-input-inline" style="margin: 10px;text-align: left;">
					<button type="button" class="layui-btn" style="background-color: #9AC747" id="test2">上传图片</button>
				</div>

                <div class="layui-upload" style="text-align: left"><span id="demo2"></span></div>
            </div>
			<p style="font-size: 12px;">以上信息仅供集充充工作人员可见,请放心填写</p><br/>
			<button type="reset" class="layui-btn layui-btn-primary"style="width: 45%;">重置</button>
			<button class="layui-btn " style="background-color: #9AC747;width: 45%;" id="test9" type="button" onclick="inserta()" >确定</button>
			<p style="height: 20px;"></p>
		</form>
	</div>

<script type="text/javascript">

    var fileIds=[];
    var resultURL="";
	layui.use(['form','upload'], function(){
	  var form = layui.form
      var $ = layui.jquery
      , upload = layui.upload
	  ,layer = layui.layer
	    //监听提交
		  form.on('submit(demo1)', function(data){
		    layer.alert(JSON.stringify(data.field), {
		      title: '最终的提交信息'
		    })
		    return false;
		  });



        upload.render({
            elem: '#uploadZZ'
            ,url: '${base}/WechatCar/upload'
            ,multiple: true
            , before: function (obj) { //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                layer.load(); //上传loading

            }
            ,data: {
                isCarIndex:1
            }
            , done: function (res) {
                layer.msg(res.msg)
                layer.closeAll('loading'); //关闭loading
                $("#uploadZZ").html('<img src="${base}/weUser/getPhoto?path='+res.data.url+'">')
                resultURL=res.data.fileId;
            }
            , error: function (index, upload) {
                layer.closeAll('loading'); //关闭loading
            }
        });



        //多图片上传
        upload.render({
            elem: '#test2'
            ,url: '${base}/WechatCar/upload'
            ,multiple: true
            ,
            before:function (obj){
                layer.load(); //上传loading
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo2').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img">')
                });
            }
            ,auto:true
            ,data: {
                isCarIndex:2
            }
            //上传完毕回调函数
            ,done: function(res){
                layer.closeAll('loading'); //关闭loading
                layer.msg(res.msg)
                fileIds.push(res.data.fileId);
            } , error: function (index, upload) {
                layer.closeAll('loading'); //关闭loading
            }
        });
});
    function inserta(){

        var formData={};
        formData.ptName=$("#ptName").val();
        formData.callName=$("#callName").val();
        formData.callPhone=$("#callPhone").val();
        formData.carType=$("#carType").val();
        formData.carNumber=$("#carNumber").val();
        formData.carName=$("#carName").val();
        formData.carSize=$("#carSize").val();
        formData.carKm=$("#carKm").val();
        formData.base=$("#base").val();
        formData.insure=$("#insure").val();
        formData.num=$("#num").val();
        formData.carMoeny=$("#carMoeny").val();
        $.ajax({
            type: "POST",
            data:{filesId: fileIds,param:JSON.stringify(formData),resultURL:resultURL},
            url: "${base}/WechatCar/insert",

            success: function (data) {
                data=JSON.parse(data);
                if (data.flag===true){
                    alert("添加成功")
                    window.location.href="${base}/WechatCar/success.html"
                }else{
                    alert("添加失败")
                }
            }

        });
    }

</script>
	</body>
</html>